package com.bjpowernode.springboot.config;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.filter.CharacterEncodingFilter;

@Configuration //将此类定义为配置文件
public class SystemConfig {

    @Bean
    public FilterRegistrationBean characterEncodingRegistrationBean(){

        //创建字符编码过滤器
        CharacterEncodingFilter characterEncodingFilter=new CharacterEncodingFilter();
        //设置强制使用指定的字符编码
        characterEncodingFilter.setForceEncoding(true);
        //设置指定字符编码
        characterEncodingFilter.setEncoding("UTF-8");

        FilterRegistrationBean bean=new FilterRegistrationBean();

        //设置字符编码过滤器
        bean.setFilter(characterEncodingFilter);
        //设置字符编码过滤器路径
        bean.addUrlPatterns("/*");

        return bean;
    }
}
